package com.google.code.flickrlite;

import java.util.HashMap;
import java.util.Map;

/**
 * A photo is represented by a title, the date at which it was taken and a
 * URL.
 */
public class Photo {
	
	static final String IMAGE_FORMAT_JPG = "jpg";

	static final String PHOTO_IMAGE_URL = "http://farm%s.static.flickr.com/%s/%s_%s%s.%s";
	
	private String id;
	private String secret;
	private String server;
	private String farm;
	private String title;
	private String date;
	private String license;
	private String originalSecret;
	private String originalFormat;

	private Map<PhotoSize, Dimesions> sizes = new HashMap<PhotoSize, Dimesions>();

	public Photo() {
	}

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getFarm() {
		return farm;
	}

	public void setFarm(String farm) {
		this.farm = farm;
	}

	public String getOriginalFormat() {
		return originalFormat;
	}

	public void setOriginalFormat(String originalFormat) {
		this.originalFormat = originalFormat;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public void setLicense(String license) {
		this.license = license;
	}

	public void setOriginalSecret(String originalSecret) {
		this.originalSecret = originalSecret;
	}

	/**
	 * Returns the title of the photo, if specified.
	 * 
	 * @return The title of the photo. The returned value can be empty or
	 *         null.
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Returns the date at which the photo was taken, formatted in the
	 * current locale with the following pattern: MMMM d, yyyy.
	 * 
	 * @return The title of the photo. The returned value can be empty or
	 *         null.
	 */
	public String getDate() {
		return date;
	}

	public String getLicense() {
		return license;
	}

	public String getOriginalSecret() {
		return originalSecret;
	}

	public Map<PhotoSize, Dimesions> getSizes() {
		return sizes;
	}

	/**
	 * Returns the URL to the photo for the specified size.
	 * 
	 * @param photoSize
	 *            The required size of the photo.
	 * 
	 * @return A URL to the photo for the specified size.
	 */
	public String getUrl(PhotoSize photoSize) {
		if (photoSize == PhotoSize.Original) {
			return String.format(PHOTO_IMAGE_URL, farm, server, id,
					originalSecret, photoSize.size(), originalFormat);
		} else {
			return String.format(PHOTO_IMAGE_URL, farm, server, id,
					secret, photoSize.size(), IMAGE_FORMAT_JPG);
		}
	}

	@Override
	public String toString() {
		return title + ", " + date + " @" + id;
	}

	public int describeContents() {
		return 0;
	}

}